﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using PMS.BusinessFacade;
using PMS.EntityManage;
using PMS.Common;
using PMS.EntityQuery;
using System.Data.SqlClient;
using System.Collections.Generic;

using BusinessFacade;
using EntityManage;

public partial class Modules_Personal_EvaluateTargetHistory : System.Web.UI.Page
{
    IPerf_Personal_EvaluateHandler evaluateHandler = new Perf_Personal_EvaluateManage();
    IPerf_Personal_EvaluateDtlHandler evaluateDtlHandler = new Perf_Personal_EvaluateDtlManage();

    ISys_OrganizationHandler organizationHandler = new Sys_OrganizationManage();

    IPerf_Personal_TargetOwnerHandler targetOwnerHandler = new Perf_Personal_TargetOwnerManage();
    DataBase db = new DataBase();

    ISys_UserHandlerExt userHandlerExt = new Sys_UserManageExt();
    IPerf_Personal_EvaluateHandlerExt evaluateHandlerExt = new Perf_Personal_EvaluateManageExt();
    IPerf_Personal_FinalAssignHandler finalAssignHandler = new Perf_Personal_FinalAssignManage();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        { 
            ViewState["OrderBy"] = "Id";
            ViewState["Accending"] = "desc";
            dataBind();

        }
    }

    public string GetUserName(object id)
    {
        return userHandlerExt.GetUserNameByID(int.Parse(id.ToString()));
    }

    public string GetTargetOwner(object id)
    {
        string name = string.Empty;
        Perf_Personal_TargetOwnerQuery query = targetOwnerHandler.GetPerf_Personal_TargetOwnerQuery(int.Parse(id.ToString()));
        if (query != null)
        {
            name = query.Name;
        }
        return name;
    }

    public void dataBind()
    {
        if (Request["ID"] != null)
        {
            string sqlStr = @"select t.Name,edtl.Evaluate_ID, edtl.Score,edtl.User_ID,edtl.ID,edtl.Target_ID,edtl.InsertTime,edtl.Remark
from Perf_Personal_EvaluateDtl edtl 
inner join Perf_Personal_Target t on t.ID=edtl.Target_ID where  Evaluate_ID=@Evaluate_ID";

            DataTable dtCount = db.RunSqlTab(sqlStr, new SqlParameter[] { new SqlParameter("@Evaluate_ID", Request["ID"]) });

            DataTable dt = db.GetDataTableByIndex(sqlStr, new SqlParameter[] { new SqlParameter("@Evaluate_ID", Request["ID"]) }, AspNetPager.StartRecordIndex - 1, AspNetPager.PageSize);

            if (dtCount != null && dtCount.Rows.Count > 0)
            {
                AspNetPager.RecordCount = dtCount.Rows.Count;
            }
            gvTargetEvalate.DataSource = dt;
            gvTargetEvalate.DataBind();
        }
    }


    protected void gvTargetEvalate_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "del")
        {
            try
            {
                int evDtlID = 0;
                int.TryParse(e.CommandArgument.ToString(), out evDtlID);
                evaluateDtlHandler.DeletePerf_Personal_EvaluateDtl("ID=@ID", new SqlParameter[] { new SqlParameter("@ID", evDtlID.ToString()) });
               
                Jscript.AlertInAjax("操作成功!", UpdatePanel1);
                dataBind();
            }
            catch { Jscript.AlertInAjax("操作失败!", UpdatePanel1); }
        }
    }

    protected void gvTargetEvalate_RowDataBound(object sender, GridViewRowEventArgs e)
    {

    }

    protected void gvTargetEvalate_Sorting(object sender, GridViewSortEventArgs e)
    {
        if (e.SortExpression.ToLower() == ViewState["OrderBy"].ToString().ToLower())
        {
            if (ViewState["Accending"].ToString().ToLower() == "asc")
            {
                ViewState["Accending"] = "desc";
            }
            else
            {
                ViewState["Accending"] = "asc";
            }
        }
        else
        {
            ViewState["OrderBy"] = e.SortExpression;
        }

        dataBind();
    }

    protected void AspNetPager_PageChanged(object src, EventArgs e)
    {

        dataBind();
    }

}
